import { ITrade } from './trade'
import { ETradeChannel, EPaymentBrand } from '@shared/enums'
import { IPagination } from './pagination'
import { IQueryParams } from './queryParams'

/** 暂扣释放 */
export interface ITradeHoldReq {
  intStoreCode: string,
  origOrderNum: string
  reason: string,
  remark: string,
}

export interface ITradeReleaseReq {
  reason: string,
  remark: string,
}

export interface ITradeHoldCheckReq {
  intStoreCode: string
  origOrderNum: string
  remark?: string
}

export interface IHoldReleaseDetailObj {
  trans: ITrade,
  riskStatus: ERiskStatus
  holdDetail: IHoldReleaseDetail,
  releaseDetail: IHoldReleaseDetail,
}

export interface ICodeMsgResponse {
  code: string,
  msg: string,
}

export enum ERiskStatus {
  'Holded' = 'holded',
  'Released' = 'released',
}

export enum ERiskStatusMap {
  'holded' = 'OPERATION.HOLD',
  'released' = 'OPERATION.RELEASE',
}

export enum EHoldErrorCode {
  Holded = 'MSG_CODE.BIZ.TRANS_HOLDED',
}

export interface IHoldReleaseDetail {
  riskTime: string,
  reason: string,
  operator: string,
  remark: string,
}

export enum EHoldReason {
  '01' = 'OPERATION.HOLD.REASON.RISKTRADE',
  '02' = 'OPERATION.HOLD.REASON.FAKECARD',
}

export enum EReleaseReason {
  '03' = 'OPERATION.RELEASE.REASON.NORISK',
  '04' = 'OPERATION.RELEASE.REASON.HOLDTOOLONG'
}

/** 差错 */
export interface IChargeBack {
  /** 案例编号 */
  disputeNum: string
  storeName: string
  storeNameEN: string

  /** ARN */
  acqReferData: string

  /** 卡品牌 */
  cardBrand: ETradeChannel

  /** 差错时间 */
  transDateTime: string

  /** 差错类型 */
  transCode: EChargeBackTransCode

  /** 渠道 */
  channel: EPaymentBrand,

  /** 差错金额 */
  transAmt: number

  /** 扣款金额 */
  billingAmt: number

  /** 币种 */
  transCurr: string

  /** 扣款币种 */
  billingCurr: string

  /** 状态 */
  processFlag: string /** ProcessTypeMap */

  /** 处理方式  */
  processType: EChargeBackProcessType

  /** 检索参考号 */
  refNum: string

  /** 卡号 */
  cardNum: string

  /** 授权码 */
  authCode: string

  /** ARN */
  ARN: string

  /** 原因代码 后端返回就是 resonCode */
  resonCode: string

  /** 操作用户 */
  operator: string

  /** 备注 */
  remark: string

  /** 原交易 */
  origTrans?: ITrade

  /** 扣款金额 */
  upTransAmt: number

  /** 扣款金额币种 */
  upTransCurr: string

  /** 再请款金额 */
  downTransAmt: number

  /** 再请款金额币种 */
  downTransCurr: string

  /** 再请款金额 */

  /** 差错日期 */
  createdAt: string,
  updatedAt: string,
}

export enum EChargeBackTransCode {
  /** 调单 Retrival */
  RTV = 'RTV',
  /** 退单 Chargeback */
  FCB = 'FCB',
  /** 二次退单 Second-Chargeback */
  SCB = 'SCB',
  /** 退回 Reject */
  REJ = 'REJ',
}

export enum EChargeBackStatus {
  /** 待处理 */
  Todo = '0',

  /** 已完成 */
  Done = '1',

  /** 已关闭 */
  Closed = '2',
}

/** 处理方式 */
export enum EChargeBackProcessType {
  /** 未处理, 前端不展示 */
  // NotHandled = '0',

  /** 商户扣款 */
  MerchantDebit = '1',

  /** 再请款 */
  Representment = '2',

  /** 调单回复 */
  Retrievaled = '3',

  /** 调单回复, 同已调单  */
  // RetrievalRespond = 'RetrievalRespond',

  /** 仲裁 */
  Arbitrate = '4',

  /** 扣款再请款 */
  DebitAndRepresent = '5',

  /** 关闭 */
  Close = '9',
}

export const ChargeBackStatusMap = {
  0: 'OPERATION.CHARGEBACK.PROCESSFLAG.NOTHANDLED',
  1: 'OPERATION.CHARGEBACK.PROCESSFLAG.DONE',
  2: 'OPERATION.CHARGEBACK.PROCESSFLAG.CLOSED',
}

export const ChargeBackProcessTypeMap = {
  // 0: 'OPERATION.CHARGEBACK.PROCESSTYPE.NOTHANDLED',
  1: 'OPERATION.CHARGEBACK.PROCESSTYPE.MERCHANTDEBIT',
  2: 'OPERATION.CHARGEBACK.PROCESSTYPE.REPRESENTMENT',
  3: 'OPERATION.CHARGEBACK.PROCESSTYPE.RETRIEVALED',
  4: 'OPERATION.CHARGEBACK.PROCESSTYPE.ARBITRATE',
  5: 'OPERATION.CHARGEBACK.PROCESSTYPE.DEBITANDREPRESENT',
  9: 'OPERATION.CHARGEBACK.PROCESSTYPE.CLOSE',
}

export const ChargeBackTransCodeMap = {
  /** 调单 */
  RTV: 'OPERATION.CHARGEBACK.TRANSCODE.RETRIVAL',
  /** 退单 */
  FCB: 'OPERATION.CHARGEBACK.TRANSCODE.CHARGEBACK',
  /** 二次退单 */
  SCB: 'OPERATION.CHARGEBACK.TRANSCODE.SECOND-CHARGEBACK',
  /** 退回 */
  REJ: 'OPERATION.CHARGEBACK.TRANSCODE.REJECT',
}

export const ProcessFlagMap = {
  0: '未处理',
  1: '已完成',
  2: '已关闭',
}

export const ReasonCodeMap = {
  2000:	'General – invalid Chargeback',
  2001:	'Invalid Acquirer reference number on Chargeback',
  2002:	'Non-receipt of required documentation to support Chargeback',
  2003:	'Correct transaction date provided',
  2004:	'Correct merchant description provided (DBA)',
  2005:	'Correct merchant location provided',
  2006:	'Incorrect transaction date provided on Chargeback',
  2007:	'Transaction did not exceed Network (Card Acceptor) floor limit',
  2008:	'Transaction authorized by Issuer',
  2009:	'No error in addition of sale – amount correct in original transaction',
  2010:	'No proof of altered amount (customer stated in Chargeback that amount had been altered)',
  2011:	'Credit previously issued',
  2012:	'Original transaction was valid',
  2700:	'Per local regulation proof of government id validation can not be provided',
  2701:	'Valid ATM Journal Roll/Audit Tape Provided',
  4516:	'Non-fulfillment of request for information (Request for Support Not Fulfilled)',
}

/** 查询列表请求体 */
export interface IChargeBackQueryParams extends IQueryParams {
  startTime?: string
  endTime?: string
  orderNum?: string
  chargeAmtFrom?: number
  chargeAmtTo?: number
  currency?: string
  channel?: string
  refNum?: string
  codeNum?: string
  authCode?: string
  ARN?: string
  reasonCode?: string
  type?: string
  handleMethod?: string
  status?: string
  insCode?: string
  agentCode?: string
  intMerCode?: string
  intStoreCode?: string
}

/** 查询列表返回数据 */
export interface IChargeBackPagination extends IPagination {
  data: IChargeBack[]
}

/** 处理请求体 */
export interface IChargeBackOperateReq {
  /** 编号 */
  disputeNum: string
  /** 处理方式 */
  processType: EChargeBackProcessType
  /** 操作备注 */
  remark: string
  /** 金额 */
  transAmt?: number
  /** 原因代码 */
  reasonCode?: string
  /** MMT */
  memMessTxt?: string
  /** 文本标志 */
  docIndicator?: boolean
}

/** 请求结构体类 */
export class OperateBody {
  remark: string
  amt: number
  reasonCode: string
  MMT: string
  docIndicator = true
}

export enum EChargeOperateBodyI18n {
  remark = 'OPERATION.CHARGEBACK.OPERATEREMARK',
  amt = 'TRADE.CHARGEBACK.AMT',
  reasonCode = 'OPERATION.CHARGEBACK.REASONCODE',
  MMT = 'OPERATION.CHARGEBACK.MMT',
  docIndicator = 'OPERATION.CHARGEBACK.DOCINDICATOR'
}

